package cn.org.timespace.easyframe.util.sms.telecom.send;

import java.io.IOException;

import cn.org.timespace.easyframe.util.sms.telecom.smgp.Client;
import cn.org.timespace.easyframe.util.sms.telecom.smgp.bean.Result;
import cn.org.timespace.easyframe.util.sms.telecom.smgp.bean.Submit;
import cn.org.timespace.easyframe.util.sms.telecom.smgp.bean.SubmitBatch;

/**
 * ������Ϣ
 * */
public class SendSms {
	//��ȡ���ò���
	/*private static final String host = SMGPPropertie.getProperty("smgp.host");//l�ӵ�ַ
	private static final int port = Integer.parseInt(SMGPPropertie.getProperty("smgp.port"));//l�Ӷ˿�
	private static final String account = SMGPPropertie.getProperty("smgp.clientid");//�ʺ�
	private static final String passwd = SMGPPropertie.getProperty("smgp.sharedSecret");//����
	private static final String spid = SMGPPropertie.getProperty("smgp.srcTermId");//��ҵ����
	private static final String spnum = SMGPPropertie.getProperty("smgp.chargeTermId");//�ƷѺ���
	private static final String productid=SMGPPropertie.getProperty("smgp.productid");*/
	private static final String host = "115.168.94.48";//l�ӵ�ַ
	private static final int port = 8891;//l�Ӷ˿�
	private static final String account = "LTSW";//�ʺ�
	private static final String passwd = "LTSW123";//����
	private static final String spid = "10659607001";//��ҵ����
	private static final String spnum = "10659607001";//�ƷѺ���
	private static final String productid="112000000000000001032";
	/**
	 * ����  Ⱥ������Ϣ
	 * @param String[] destnum notNull  Ŀ�����   ���Ŀ�����
	 * @param String content Null     ��������
	 * */
	public static Result Send(String[] destnum,String content) throws IOException{
		//��ʼ��client
		Client client = new Client(host, port, 2,account, passwd,spid, 0);
		Result resultc = client.Login();
		if(resultc.ErrorCode!=0)
			System.out.println("��������l��ʧ�ܣ�");
		else
			System.out.println("��������l�ӳɹ���");
		//����submit
		SubmitBatch submit =new SubmitBatch();
		submit.setSrcTermid(spnum);
		submit.setDestTermid(destnum);
		submit.setMsgContent(content.getBytes("iso-10646-ucs-2"));
		submit.setMsgFormat(8);
		if (productid!=null) submit.setProductID(productid);
		
		// ���Ͷ���
		Result result = client.SendBatch(submit);
		System.out.println("result:"+result.ErrorCode);
		//�˳�
		client.Close();
		return result;
	}
	
	/**
	 * ���Ͷ���Ϣ
	 * @param String destnum notNull  Ŀ����� 
	 * @param String content Null     ��������
	 * */
	public static Result Send(String destnum,String content) throws IOException{
		//��ʼ��client
		Client client = new Client(host, port, 2,account, passwd,spid, 0);
		Result resultc = client.Login();
		if(resultc.ErrorCode!=0)
			System.out.println("��������l��ʧ�ܣ�");
		else
			System.out.println("��������l�ӳɹ���");
		//����submit
		Submit submit =new Submit();
		submit.setSrcTermid(spnum);
		submit.setDestTermid(destnum);
		submit.setMsgContent(content.getBytes("iso-10646-ucs-2"));
		submit.setMsgFormat(8);
		if (productid!=null) submit.setProductID(productid);
		
		// ���Ͷ���
		Result result = client.Send(submit);
		System.out.println("result:"+result.ErrorCode);
		//�˳�
		client.Close();
		return result;
	}

}
